<?php
namespace app\tools\logic;
use think\Request;

class CommonLogic{
        //token验证
        static function checkToken(Request $request){
                $token = $request->header('token');
                if(!$token){
                        return ;
                }
                // echo $token;
        }
        
        //签名验证
	static function signAuth($signStr="", $signTime=""){
		$signTime = input('signTime',0);
                $signStr = input('signStr','');
                if(!$signTime){
                	return 101;
                }
                if(!$signStr){
                	return 102;
                }

                $cof = config('tools');
                $sign_exp_time = $cof['sign_exp_time'];
                //时间验证
                if($sign_exp_time && (time()-$signTime>$sign_exp_time || $signTime-time()>$sign_exp_time)){
                	return 103;
                }

		$appid = $cof['tools_appid'];
		$secret	=	$cof['tools_secret'];

		$strs = $appid.$secret.$signTime;
		// echo MD5($strs);
		if($signStr!=MD5($strs)){
			return 100;
		}else{
			return 0;
		}
	}

}
